<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" pageEncoding="utf-8" language="java" %>
<header class="main-header">
    <a href="all-admin-index.html" class="logo">
        <span class="logo-mini"><img src="../img/logo.png"></span>
        <span class="logo-lg">
                    <img src="../img/export.png">
                    <i> SaaS外贸进出口平台</i>
                </span>
    </a>

    <nav class="navbar navbar-static-top">
        <a href="#" class="sidebar-toggle" data-toggle="offcanvas" role="button">
            <span class="sr-only">Toggle navigation</span>
        </a>
        <div style="float:left; display:inline;text-align: center;padding-top: 15px">
            <iframe scrolling="no" src="https://tianqiapi.com/api.php?style=tb&skin=pitaya&color=FFFFFF" frameborder="0"
                    width="350" height="30" allowtransparency="true"></iframe>
        </div>
        <div style="float:right;padding-top: 13px ;display:inline">
            <a onclick="setSidebarActive(this)" class="label label-primary pull-right" href="/notice/toFeedback.do" target="iframe">
                反馈与建议
            </a>
        </div>
        <div class="navbar-custom-menu">
            <ul class="nav navbar-nav">
                <li class="dropdown messages-menu">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                        <i class="fa fa-envelope-o"></i>
                        <%--邮件数量--%>
                        <span class="label label-success" id="emailNum"></span>
                    </a>
                    <ul class="dropdown-menu">
                        <li class="header" id="emailLabel"></li>
                        <li>
                            <ul class="menu" id="emailMenu">

                            </ul>
                        <li class="footer"><a onclick="setSidebarActive(this)" href="/notice/toEmailBox.do"
                                              target="iframe">See All Messages</a></li>
                    </ul>
                </li>
                <!-- Notifications: style can be found in dropdown.less -->
                <li class="dropdown notifications-menu">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                        <i class="fa fa-bell-o"></i>
                        <span class="label label-warning"></span>
                    </a>
                    <ul class="dropdown-menu">
                        <li class="header">你有0个新消息</li>
                        <li>
                            <ul class="menu">
                                <%--<li>--%>
                                    <%--<a href="#">--%>
                                        <%--<i class="fa fa-user text-red"></i> You changed your username--%>
                                    <%--</a>--%>
                                <%--</li>--%>
                            </ul>
                        </li>
                        <li class="footer"><a href="#">View all</a></li>
                    </ul>
                </li>
                <!-- Tasks: style can be found in dropdown.less -->
                <li class="dropdown tasks-menu">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                        <i class="fa fa-flag-o"></i>
                        <span class="label label-danger"></span>
                    </a>
                    <ul class="dropdown-menu">
                        <li class="header">你有0个新任务</li>
                        <li>
                            <!-- inner menu: contains the actual data -->
                            <ul class="menu">
                                <%--<li>--%>
                                    <%--<!-- Task item -->--%>
                                    <%--<a href="#">--%>
                                        <%--<h3>--%>
                                            <%--Design some buttons--%>
                                            <%--<small class="pull-right">20%</small>--%>
                                        <%--</h3>--%>
                                        <%--<div class="progress xs">--%>
                                            <%--<div class="progress-bar progress-bar-aqua" style="width: 20%"--%>
                                                 <%--role="progressbar" aria-valuenow="20" aria-valuemin="0"--%>
                                                 <%--aria-valuemax="100">--%>
                                                <%--<span class="sr-only">20% Complete</span>--%>
                                            <%--</div>--%>
                                        <%--</div>--%>
                                    <%--</a>--%>
                                <%--</li>--%>

                            </ul>
                        </li>
                        <li class="footer">
                            <a href="#">View all tasks</a>
                        </li>
                    </ul>
                </li>
                <!-- User Account: style can be found in dropdown.less -->
                <li class="dropdown user user-menu">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                        <img src="../img/user2-160x160.jpg" class="user-image" alt="User Image">
                        <span class="hidden-xs"> ${sessionScope.loginUser.userName}</span>
                    </a>
                    <ul class="dropdown-menu">
                        <!-- User image -->
                        <li class="user-header">
                            <img src="../img/user2-160x160.jpg" class="img-circle" alt="User Image">

                            <p>
                                ${sessionScope.loginUser.userName}
                            </p>
                        </li>
                        <!-- Menu Body
                <li class="user-body">
                    <div class="row">
                        <div class="col-xs-4 text-center">
                            <a href="#">Followers</a>
                        </div>
                        <div class="col-xs-4 text-center">
                            <a href="#">Sales</a>
                        </div>
                        <div class="col-xs-4 text-center">
                            <a href="#">Friends</a>
                        </div>
                    </div>
                </li>-->
                        <!-- Menu Footer-->
                        <li class="user-footer">
                            <div class="pull-left">
                                <a href="/system/user/toVerify.do" class="btn btn-default btn-flat">修改密码</a>
                            </div>
                            <div class="pull-right">
                                <a href="/logout.do" class="btn btn-default btn-flat">注销</a>
                            </div>
                        </li>
                    </ul>
                </li>

            </ul>

        </div>
    </nav>
</header>
<script>
    function timeAgo(timeA) {

        let stamp = new Date().getTime() - timeA;
        let time = (stamp / 1000);

        if (null != time && "" != time) {
            if (time < 60) {
                time = "1分钟"
            } else if (time > 60 && time < 60 * 60) {
                time = parseInt(time / 60.0) + "分钟";
            } else if (time >= 60 * 60 && time < 60 * 60 * 24) {
                time = parseInt(time / 3600.0) + "小时";
            } else if (time >= 60 * 60 * 24) {
                time = parseInt(time / 3600.0 / 24) + "天";
            }
        }
        return time;
    }
</script>
<script>
    $(function () {
        function showResult() {
            $.ajax({
                url: "/notice/getAJAXEmail.do",
                success: function (noteList) {
                    console.log(noteList);

                    $("#emailNum").html(noteList.length);
                    let emailMessage = "你有" + noteList.length + "个邮件";

                    $("#emailLabel").html(emailMessage);


                    let emailList = '';
                    for (let n of noteList) {

                        console.log(n.sendtime);
                        emailList += '<li>';
                        emailList += '<a onclick="setSidebarActive(this)" target="iframe" href="${ctx}/notice/oneEmail.do?reportid=' + n.reportid + '">';
                        emailList += '<div class="pull-left">';
                        emailList += '<img src="' + n.sendphoto + '" class="img-circle" alt="User Image">';
                        emailList += '</div>';
                        emailList += '<h4>';
                        emailList += n.sendname;
                        emailList += '<small><i class="fa fa-clock-o">'+timeAgo(n.sendtime)+'</i></small>';
                        emailList += '</h4>';
                        emailList += '<p>' + n.content + '</p>';
                        emailList += '</a>';
                        emailList += '</li>';
                    }
                    $("#emailMenu").html(emailList);

                },
                dataType: "json",
                async: true,
                timeout: 3000
            })
        }

        //循环操作
        setInterval(function () {
            showResult();
        }, 4000)
    })

</script>


<!-- 页面头部 /-->

